package Servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONException;
import org.json.JSONObject;

import DAL.Entites.GameImage;
import DAL.JDBC.DBConn;
import DAL.JDBC.GameImageJDBC;


public class GetGameImages extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public GetGameImages() {
        super();
    }

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		JSONObject result = new JSONObject();	
		GameImageJDBC gameImageJDBC = new GameImageJDBC(DBConn.getConnection());	
		
		int gameId = Integer.parseInt(request.getParameter("gameId"));
		List<GameImage> images = gameImageJDBC.listImagesByGameId(gameId);
		try {
			result.put("images", images);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		PrintWriter pw = response.getWriter();
		pw.write(result.toString());
	}

}
